<template>
	<view class="page">
		<template v-if="isLogin">
			
			<template v-if="loadingState.default">
				<loading :loadingState="loadingState"></loading>
			</template>
			
			<template v-else>
				<view class="body">
					<template v-if="detail">
						<view class="map">
							<map id="map" :longitude="detail.pcdata.gcj02_lng" :latitude="detail.pcdata.gcj02_lat"
								:markers="markers" scale="16" show-location style="width: 100%; height: 150px;"></map>
						</view>
						<view class="env-params">
							<image class="bg-img" src="@/static/images/public_addinfo.png" mode="widthFix">
							<view class="contain">
								<view class="hd-title">环境数据</view>
								<view class="data-list ">
									<view class="item">
										<view class="label">经度</view>
										<text class="val">{{detail.pcdata.d2ms_lng}}</text>
									</view>
									<view class="item">
										<view class="label">纬度</view>
										<text class="val">{{detail.pcdata.d2ms_lat}}</text>
									</view> 
									<view class="item">
										<view class="label">海拔</view>
										<text class="val">{{detail.pcdata.altitude|toFixedN(2)}}m</text>
									</view>
									<view class="item">
										<view class="label">天气情况</view>
										<text class="val">{{detail.pcdata.weather}}</text>
									</view>
									<view class="item">
										<view class="label">空气温度</view>
										<text class="val">{{detail.pcdata.temperature}}°c</text>
									</view>
									<view class="item">
										<view class="label">空气湿度</view>
										<text class="val">{{detail.pcdata.humidity}}%</text>
									</view>
								</view>
					
								<view class="local-area">
									<view class="icon iconfont icon-daohang f-s40">&#xe648;</view>
									<view class="text">{{detail.pcdata.address}}</view>
								</view>
							</view>
						</view>
						
						<view class="detail-wrap m-b2">
							<view class="detail-item">
								<view class="label">审核状态：</view>
								<view class="detail-input">
									<view class="content">
										<view class="val"> 
											<text v-if="detail.pcdata.status==2" class="f-blue">待审核</text>
											<text v-if="detail.pcdata.status==1" class="f-green">已审核</text>
											<text v-if="detail.pcdata.status==3" class="f-red">审核不通过</text>
										</view>
									</view>
								</view>
							</view>
							<view class="detail-item">
								<view class="label">联系电话：</view>
								<view class="detail-input">
									<view class="content">
										<view class="val">{{detail.pcdata.phone}}</view>
									</view>
								</view>
							</view>
							<view class="detail-item">
								<view class="label">发现蚁巢数：</view>
								<view class="detail-input">
									<view class="content">
										<view class="val">{{detail.pcdata.nests_count}}</view>
										<view class="link">个</view>
									</view>
								</view>
							</view>
							<view class="detail-item">
								<view class="label">采集时间：</view>
								<view class="detail-input">
									<view class="content">
										<view class="val">{{detail.pcdata.create_time}}</view>
									</view>
								</view>
							</view>
						</view>
						
						<!-- 图片 -->
						<view class="form-wrap m-b2">
							<view class="upload-pic-item">
								<view class="label">红火蚁巢照片</view>
								<view class="form-upload-pic">
									<template>
										<view class="img-item" v-for="(item,index) in detail.pcFiles" :key="index">
											<image src="@/static/images/filter_bg.png" mode="widthFix">
												<!-- 占位 -->
											</image>
											<view class="img-wrap" @click="preview(index)">
												<image class="img" :src="web_host+'/image/image?path='+item.file_path" mode="widthFix"></image>
											</view>
										</view>
									</template>
								</view>
							</view>
						</view>
						
	 
					</template>
					
					<template v-else>
						<empty msg="暂无信息"></empty>
					</template>
				</view>
				
				<!-- 底部 -->
				<view class="footer">
					<view class="fix-wrap bottom">
						<view class="form-lay-btn" @click="openNavigation"><view class="iconfont f-s40">&#xe648;</view><text>导航前往</text></view>
					</view>
				</view>
			</template>
			 
			
		</template>
	</view>
</template>

<script>
	import loading from '@/components/loading-more.vue'
	import empty from '@/components/empty.vue'
	import {HTTP_REQUEST_URL} from '@/config.js'
	import {
		previewImage,
		replaceStr,
		d2Dms
	} from '@/common/util.js'
	export default {
		name: 'name',
		data() {
			return {
				isLogin: true,
				id: '',
				loadingState: {
					default: true
				},
				detail: {},
				web_host:HTTP_REQUEST_URL,
				markers:[]
			}


		},
		filters:{
			toFixedN:function(val,n){
				val=Number(val);
				return val.toFixed(n);
			}
		},
		async onLoad(params) {
			this.id = params.id;
			this.isLogin = await this.$loginState('check');
			if (this.isLogin) {
				this.getDataInfo();
			}

		},
		async onShow() {

		},
		methods: {
			getDataInfo: async function() {
				let res = await this.$api.ssp_api.getDataInfo({
					id: this.id
				}) 
				if (res.data.ret == 0) {
					this.loadingState.default=false;
					res.data.data.pcdata.phone=replaceStr(res.data.data.pcdata.phone,3,"****")  
					res.data.data.pcdata.d2ms_lat=d2Dms(parseFloat(res.data.data.pcdata.gcj02_lat).toFixed(6));   // d2Dms方法 转为度分秒格式;
					res.data.data.pcdata.d2ms_lng=d2Dms(parseFloat(res.data.data.pcdata.gcj02_lng).toFixed(6));    // d2Dms方法 转为度分秒格式
					res.data.data.pcdata.accuracy=res.data.data.pcdata.accuracy;
					res.data.data.pcdata.altitude=res.data.data.pcdata.altitude;
					
					
					this.detail = res.data.data;					
					
					this.markers.push({
						id: 0,
						latitude: res.data.data.pcdata.gcj02_lat,
						longitude: res.data.data.pcdata.gcj02_lng,
						iconPath: '../../static/images/mark4.png',
						width: '60',
						height: 40
					})
				}else{
					this.loadingState.default=false;
					this.detail=null;
				}
			},
			
			// 图片预览
			preview: function(idx) {
				let img_list = [];
				this.detail.pcFiles.forEach(item => {
					img_list.push(this.web_host + '/image/image?path=' + item.file_path)
				})
				previewImage({
					data: img_list,
					index: idx
				})
			},
			
			// 打开导航
			openNavigation: function() {
				uni.openLocation({
					latitude: parseFloat(this.detail.pcdata.gcj02_lat),
					longitude: parseFloat(this.detail.pcdata.gcj02_lng),
					name: this.detail.pcdata.address,
					address: this.detail.pcdata.address,
					scale: 18
				})
			},
		},
		components: {
			loading,
			empty
		},

		computed: {

		},
		watch: {

		}

	}
</script>

<style lang="less" scoped>
	.env-params {
		position: relative;
		height: 500rpx; 
		overflow: hidden;
		.contain {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
		}

		.hd-title {
			margin: 20rpx 20rpx 10rpx;
			padding-left: 20rpx;
			border-left: 10rpx solid #f8a53f;
			font-size: 32rpx;
			font-weight: bold;
			color: #fff;
		}
	}
	
	.map{ 
		height: 150px;
		map{ 
			
			background: #f00;
		}
	}

	.form-lay-btn { 
		display: flex;
		justify-content: center;
		align-items: center;
		.iconfont{
			margin-right: 10rpx;
		}
	}

	.data-list {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		width: 94%;
		margin: 0 auto 10rpx;

		.item {
			width: 33.3%;
			margin-top: 30rpx;
			font-size: 28rpx;
			text-align: center;
			color: #fff;

			.label {
				margin-bottom: 10rpx;
				color: #fff;
			}
		}
	}

	.local-area {
		display: flex;
		width: 85%;
		margin: 30rpx auto;
		background: #f2a6b2;
		border-radius: 8rpx;

		.icon {
			flex-shrink: 0;
			width: 70rpx;
			height: 80rpx;
			text-align: center;
			line-height: 80rpx;
			color: #fff;
		}

		.text {
			padding: 15rpx 0 15rpx 0;
			color: #fff;
			font-size: 30rpx;
		}
	}

	.map-btn {
		position: fixed;
		right: 20rpx;
		bottom: 100rpx;
		width: 100rpx;
		box-shadow: 0 0 15rpx #666;
		border-radius: 50%;

		image {
			width: 100%;
		}
	}
</style>
